#ifndef __WIDGET_H__
#define __WIDGET_H__

#define WIDGET_ANIM_MAX 100

typedef enum _FBWidgetType { Image, Button } FBWidgetType;

typedef struct _FBWidget FBWidget;
typedef struct _FBWidgetLayer FBWidgetLayer;

typedef void (*FBFnWidgetPress) (FBWidget *widget);

typedef void (*FBFnWidgetLayerPostRender) (FBWidgetLayer *layer);

struct _FBWidget
{
	FBWidgetType type;
	FBWidgetLayer *layer;
	
	FBImage *image;
	FBImage *image_active;
	
	int x, y;
	bool can_active;
	bool active;
	
	FBFnWidgetPress on_press;
	
	FBImage *anim[WIDGET_ANIM_MAX];
	int anim_count, anim_index;
	int anim_x, anim_y;
	bool anim_only_active;
	
	bool dirty, always_dirty;
	
	struct _FBWidget *next;
};

struct _FBWidgetLayer
{
	int x, y;
	FBWidget *bg;
	FBWidget *widgets;
	
	struct _FBWidgetLayer *next;
	struct _FBWidgetLayer *prev;
	
	FBFnWidgetLayerPostRender on_postrender;
};

extern FBWidgetLayer *rootlayer;

FBWidget *widget_new_image (FBImage *img, int x, int y);
FBWidget *widget_new_button (FBImage *img, FBImage *active, int x, int y);
void widget_render (FBWidget *widget);

FBWidgetLayer *widget_layer_new (FBWidgetLayer *prev);
FBWidget *widget_layer_adopt (FBWidgetLayer *layer, FBWidget *widget);
void widget_layer_append (FBWidgetLayer *layer, FBWidget *widget);
void widget_layer_free (FBWidgetLayer *layer);
void widget_layer_return (FBWidgetLayer *layer);
void widget_layer_root (FBWidgetLayer *layer);
void widget_layer_render (FBWidgetLayer *layer);
void widget_layer_alldirty (FBWidgetLayer *layer);

void widget_activate_prev (FBWidgetLayer *layer);
void widget_activate_next (FBWidgetLayer *layer);
void widget_press_active (FBWidgetLayer *layer);

#endif

